<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>wltrweb.apps.mediamanager &mdash; wltrweb documentation</title>
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '0',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <link rel="shortcut icon" href="../_static/favicon.ico"/>
    <link rel="top" title="wltrweb documentation" href="../index.html" />
    <link rel="up" title="Apps" href="../apps.html" />
    <link rel="next" title="FAQ" href="../faq.html" />
    <link rel="prev" title="Apps" href="../apps.html" />
 
<script type="text/javascript" src="../templatebuiltins.js"></script>
<script type="text/javascript">
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "../ref/templates/builtins.html";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);
</script>

  </head>
  <body>

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../index.html">wltrweb documentation</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../index.html">Home</a>  |
        <a title="Table of contents" href="../contents.html">Table of contents</a>  |
        <a title="Global index" href="../genindex.html">Index</a> <!-- |
        <a title="Module index" href="../py-modindex.html">Modules</a> -->
      </div>
      <div class="nav">
    &laquo; <a href="../apps.html" title="Apps">previous</a> 
     |
    <a href="../contents.html" title="Table of contents" accesskey="U">up</a>
   |
    <a href="../faq.html" title="FAQ">next</a> &raquo;</div>
    </div>
    
    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="apps-mediamanager">
            
  <div class="section" id="wltrweb-apps-mediamanager">
<h1>wltrweb.apps.mediamanager<a class="headerlink" href="#wltrweb-apps-mediamanager" title="Permalink to this headline">¶</a></h1>
<div class="section" id="summary">
<h2>Summary<a class="headerlink" href="#summary" title="Permalink to this headline">¶</a></h2>
<p>The <tt class="docutils literal"><span class="pre">mediamanager</span></tt> app copies the specified mediafiles with a hashed filename
to a cache directory. Therefore, the files in the cache directory can could be
cached forever without losing the ability to change the mediafiles. If the
files get changed, the filenames get changed to. For example you could use the
HTTP cache control headers.</p>
</div>
<div class="section" id="settings">
<h2>Settings<a class="headerlink" href="#settings" title="Permalink to this headline">¶</a></h2>
<p><em>All values are optional.</em></p>
<div class="section" id="mediamanager-source">
<h3>MEDIAMANAGER_SOURCE<a class="headerlink" href="#mediamanager-source" title="Permalink to this headline">¶</a></h3>
<p>Default: <tt class="docutils literal"><span class="pre">MEDIA_ROOT</span></tt></p>
<p>Absolute path to the directory that is used for searching the requested files.
This directory don&#8217;t have to be accessable from the web.</p>
<p>Example:
&#8220;<tt class="docutils literal"><span class="pre">/home/media/media/</span></tt>&#8220;</p>
</div>
<div class="section" id="mediamanager-cache">
<h3>MEDIAMANAGER_CACHE<a class="headerlink" href="#mediamanager-cache" title="Permalink to this headline">¶</a></h3>
<p>Default: <tt class="docutils literal"><span class="pre">MEDIA_ROOT/cache</span></tt></p>
<p>Absolute path to the directory that is used for caching media files. This
directory must exist and it is completly controlled by the mediamanager app,
so other files will be deleted. See also <a class="reference internal" href="#mediamanager-url">MEDIAMANAGER_URL</a>.</p>
<p>Example:
&#8220;<tt class="docutils literal"><span class="pre">/home/media/media.example.com/cache/</span></tt>&#8220;</p>
</div>
<div class="section" id="mediamanager-url">
<h3>MEDIAMANAGER_URL<a class="headerlink" href="#mediamanager-url" title="Permalink to this headline">¶</a></h3>
<p>Default: <tt class="docutils literal"><span class="pre">MEDIA_URL/cache</span></tt></p>
<p>URL that handles the media served from <a class="reference internal" href="#mediamanager-cache">MEDIAMANAGER_CACHE</a>.</p>
<p>Note that this should have a trailing slash if it has a path component.</p>
<p>Good: &#8220;<tt class="docutils literal"><span class="pre">http://www.example.com/static/</span></tt>&#8221; Bad: &#8220;<tt class="docutils literal"><span class="pre">http://www.example.com/static</span></tt>&#8220;</p>
<p>Example:
&#8220;<tt class="docutils literal"><span class="pre">http://media.example.com/cache/</span></tt>&#8220;</p>
</div>
<div class="section" id="mediamanager-default-expire">
<h3>MEDIAMANAGER_DEFAULT_EXPIRE<a class="headerlink" href="#mediamanager-default-expire" title="Permalink to this headline">¶</a></h3>
<p>Default: <tt class="docutils literal"><span class="pre">60*60*24</span></tt> (1 day)</p>
<p>Time in seconds, when the mediamanger should reload files in cache.</p>
</div>
<div class="section" id="mediamanager-cleanup-interval">
<h3>MEDIAMANAGER_CLEANUP_INTERVAL<a class="headerlink" href="#mediamanager-cleanup-interval" title="Permalink to this headline">¶</a></h3>
<p>Default: <tt class="docutils literal"><span class="pre">60*60*24</span></tt> (1 day)</p>
<p>Time in seconds, when the manager should clean up unused files in the cache directory.</p>
</div>
</div>
<div class="section" id="installation">
<h2>Installation<a class="headerlink" href="#installation" title="Permalink to this headline">¶</a></h2>
<ol class="arabic simple">
<li>Add <tt class="docutils literal"><span class="pre">wltrweb.apps.mediamanager</span></tt> to <tt class="docutils literal"><span class="pre">INSTALLED_APPS</span></tt>.</li>
<li><em>(optional)</em> Set <tt class="docutils literal"><span class="pre">MEDIAMANAGER_CACHE</span></tt> and <tt class="docutils literal"><span class="pre">MEDIAMANAGER_URL</span></tt>.</li>
</ol>
</div>
<div class="section" id="usage">
<h2>Usage<a class="headerlink" href="#usage" title="Permalink to this headline">¶</a></h2>
<p><strong>Note:</strong> Don&#8217;t forget to load <tt class="docutils literal"><span class="pre">mediamanager</span></tt> templatetag.</p>
<div class="section" id="manage-style">
<h3>manage_style<a class="headerlink" href="#manage-style" title="Permalink to this headline">¶</a></h3>
<p>This tag returns a URL to the hashed file.</p>
<p>You can use the <tt class="docutils literal"><span class="pre">manage_style</span></tt> tag for serving style sheets from your
<tt class="docutils literal"><span class="pre">MEDIA_ROOT</span></tt> directory. These style sheets automaticly get compressed. For
example the file <tt class="docutils literal"><span class="pre">MEDIA_ROOT/layout.css</span></tt>:</p>
<div class="highlight-html"><div class="highlight"><pre><span class="nt">&lt;link</span> <span class="na">href=</span><span class="s">&quot;{% manage_style &#39;layout.css&#39; %}&quot;</span> <span class="na">rel=</span><span class="s">&quot;stylesheet&quot;</span> <span class="na">type=</span><span class="s">&quot;text/css&quot;</span> <span class="nt">/&gt;</span>
</pre></div>
</div>
<p>Also you can use wildcards. For more information see the Python <tt class="docutils literal"><span class="pre">glob.iglob()</span></tt>
function. All files get merged into a compressed single file. The content of
this single file gets ordered by filename. For example all css files from
<tt class="docutils literal"><span class="pre">MEDIA_ROOT/style/</span></tt> directory:</p>
<div class="highlight-html"><div class="highlight"><pre><span class="nt">&lt;link</span> <span class="na">href=</span><span class="s">&quot;{% manage_style &#39;style/*.css&#39; %}&quot;</span> <span class="na">rel=</span><span class="s">&quot;stylesheet&quot;</span> <span class="na">type=</span><span class="s">&quot;text/css&quot;</span> <span class="nt">/&gt;</span>
</pre></div>
</div>
<p>Another interesting feature is, that the mediamanger renderes style sheets like
a template. So you can use alle avalible template tags in your css files
(including <a class="reference internal" href="#manage-image">manage_image</a> and so on). But don&#8217;t forget to use the
<tt class="docutils literal"><span class="pre">{%</span> <span class="pre">load</span> <span class="pre">...</span> <span class="pre">%}</span></tt> tag. Here&#8217;s an example for using this in a css file:</p>
<div class="highlight-css"><div class="highlight"><pre><span class="nf">#header</span> <span class="p">{</span>
    <span class="k">background-image</span><span class="o">:</span> <span class="sx">url(&#39;{% manage_image &quot;img/title.png&quot; %}&#39;)</span><span class="p">;</span>
<span class="p">}</span>
</pre></div>
</div>
</div>
<div class="section" id="manage-script">
<h3>manage_script<a class="headerlink" href="#manage-script" title="Permalink to this headline">¶</a></h3>
<p>This tag works exactly like <a class="reference internal" href="#manage-style">manage_style</a>, but it compresses JavaScript
files.</p>
</div>
<div class="section" id="manage-image">
<h3>manage_image<a class="headerlink" href="#manage-image" title="Permalink to this headline">¶</a></h3>
<p>This tag returns a URL to the hashed file, too.</p>
<p>You can use the <tt class="docutils literal"><span class="pre">manage_image</span></tt> tag for serving a static file (not only images)
from your <tt class="docutils literal"><span class="pre">MEDIA_ROOT</span></tt> directory. For example the <tt class="docutils literal"><span class="pre">favicon.ico</span></tt> in
<tt class="docutils literal"><span class="pre">MEDIA_ROOT</span></tt>:</p>
<div class="highlight-html"><div class="highlight"><pre><span class="nt">&lt;link</span> <span class="na">href=</span><span class="s">&quot;{% manage_image &#39;img/favicon.ico&#39; %}&quot;</span> <span class="na">rel=</span><span class="s">&quot;shortcut icon&quot;</span> <span class="na">type=</span><span class="s">&quot;image/x-icon&quot;</span> <span class="nt">/&gt;</span>
</pre></div>
</div>
<p>Wildcards doesn&#8217;t work here, because the files don&#8217;t get compressed in any way
and they can&#8217;t merged together.</p>
<p>But rather you can use URLs instead of files in your <tt class="docutils literal"><span class="pre">MEDIA_ROOT</span></tt> directory. In
this case you have to specify an expire time, so that the cached file stays
up to date. For example you
can serve your StackOverflow profile without need of the client to download it
form another domain. The file is cached 1 hour:</p>
<div class="highlight-html"><div class="highlight"><pre><span class="nt">&lt;a</span> <span class="na">href=</span><span class="s">&quot;http://stackoverflow.com/users/393157/sven-walter&quot;</span><span class="nt">&gt;</span>
    <span class="nt">&lt;img</span> <span class="na">width=</span><span class="s">&quot;208&quot;</span> <span class="na">height=</span><span class="s">&quot;58&quot;</span> <span class="na">alt=</span><span class="s">&quot;Stack Overflow&quot;</span>
    <span class="na">src=</span><span class="s">&quot;{% manage_image_url &#39;http://stackoverflow.com/users/flair/393157.png&#39; 3600 %}&quot;</span> <span class="nt">&gt;</span>
<span class="nt">&lt;/a&gt;</span>
</pre></div>
</div>
<p>You could use the expire feature for files in your <tt class="docutils literal"><span class="pre">MEDIA_ROOT</span></tt> too, but this
doesn&#8217;t make sense.</p>
</div>
</div>
</div>


          </div>         
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h3><a href="../index.html">Table Of Contents</a></h3>
            <ul>
<li><a class="reference external" href="#">wltrweb.apps.mediamanager</a><ul>
<li><a class="reference external" href="#summary">Summary</a></li>
<li><a class="reference external" href="#settings">Settings</a><ul>
<li><a class="reference external" href="#mediamanager-source">MEDIAMANAGER_SOURCE</a></li>
<li><a class="reference external" href="#mediamanager-cache">MEDIAMANAGER_CACHE</a></li>
<li><a class="reference external" href="#mediamanager-url">MEDIAMANAGER_URL</a></li>
<li><a class="reference external" href="#mediamanager-default-expire">MEDIAMANAGER_DEFAULT_EXPIRE</a></li>
<li><a class="reference external" href="#mediamanager-cleanup-interval">MEDIAMANAGER_CLEANUP_INTERVAL</a></li>
</ul>
</li>
<li><a class="reference external" href="#installation">Installation</a></li>
<li><a class="reference external" href="#usage">Usage</a><ul>
<li><a class="reference external" href="#manage-style">manage_style</a></li>
<li><a class="reference external" href="#manage-script">manage_script</a></li>
<li><a class="reference external" href="#manage-image">manage_image</a></li>
</ul>
</li>
</ul>
</li>
</ul>

  <h3>Browse</h3>
  <ul>
    
      <li>Prev: <a href="../apps.html">Apps</a></li>
    
    
      <li>Next: <a href="../faq.html">FAQ</a></li>
    
  </ul>
  <h3>You are here:</h3>
  <ul>
      <li>
        <a href="../index.html">wltrweb documentation</a>
        
          <ul><li><a href="../contents.html">Table of contents</a>
        
          <ul><li><a href="../apps.html">Apps</a>
        
        <ul><li>wltrweb.apps.mediamanager</li></ul>
        </li></ul></li></ul>
      </li>
  </ul>  

            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="../_sources/apps/mediamanager.txt"
                     rel="nofollow">Show Source</a></li>
            </ul>
          <div id="searchbox" style="display: none">
            <h3>Quick search</h3>
              <form class="search" action="../search.html" method="get">
                <input type="text" name="q" size="18" />
                <input type="submit" value="Go" />
                <input type="hidden" name="check_keywords" value="yes" />
                <input type="hidden" name="area" value="default" />
              </form>
              <p class="searchtip" style="font-size: 90%">
              Enter search terms or a module, class or function name.
              </p>
          </div>
          <script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
          </div> 
        
      
    </div>
    
    <div id="ft">
      <div class="nav">
    &laquo; <a href="../apps.html" title="Apps">previous</a> 
     |
    <a href="../contents.html" title="Table of contents" accesskey="U">up</a>
   |
    <a href="../faq.html" title="FAQ">next</a> &raquo;</div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>